package 归并排序;

import java.util.Arrays;

//合并两个有序的数组
public class sortDemo {
    public static int[] mergerArray(int[] array1,int[] array2){
        int s1=0;
        int e1=array1.length-1;
        int s2=0;
        int i=0;
        int[] array=new int[array1.length+array2.length];
        int e2=array2.length-1;
        while(s1 <= e1 && s2 <= e2){
            if(array1[s1]< array2[s2]){
                array[i]=array1[s1];
                i++;
                s1++;
            }else{
                array[i]=array2[s2];
                i++;
                s2++;
            }
        }
        while(s1 <= e1){
            array[i]=array1[s1];
            i++;
            s1++;
        }
        while(s2 <= e2){
            array[i]=array2[s2];
            i++;
            s2++;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array1={1,3,5,7};
        int[] array2={2,4,6};
        int[] x=mergerArray(array1,array2);

        System.out.println(Arrays.toString(x));
    }
}
